import upload from '@/utils/upload'
import request from '@/utils/request'
import { buildQueryParams } from '@/utils/common'

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return upload({
    url: '/system/user/profile/avatar',
    name: data.name,
    filePath: data.filePath
  })
}

// 用户修改头像
export function changeAvatar(data) {
  return upload({
    url: '/store/user/avatar',
    name: 'avatarfile',
    filePath: data
  })
}

// 注册
export const register = (data) => {
  return request({
    url: '/store/register',
    headers: {
      isToken: false
    },
    method: 'POST',
    data
  })
}

// 申请消息列表
export function getApplyMessageList(data) {
  const queryString = buildQueryParams(data)
  return request({
    url: '/store/store/staff/review/list?'+queryString,
    method: 'GET'
  })
}

// 申请消息审核
export function applyMessagesAudit(data) {
  return request({
    url: '/store/store/staff/audit',
    method: 'POST',
    data
  })
}

// 意见反馈
export function submitFeedback(data) {
  return request({
    url: '/store/feedback',
    method: 'POST',
    data
  })
}

// 获取意见反馈出现频率选项
export function getFrequencyList() {
  return request({
    url: '/store/feedback/cycle',
    method: 'GET'
  })
}

// 更换手机号
export function updateBindMobileNumber(data) {
  return request({
    url: '/store/user/phone',
    method: 'PUT',
    data
  })
}

// 修改密码
export function updatePassword(data) {
  return request({
    url: '/store/user/updatePwd',
    method: 'PUT',
    data
  })
}

// 重置密码
export function resetPassword(data) {
  return request({
    url: '/store/user/resetPwd',
    method: 'PUT',
    data
  })
}